package com.zz.framework.core.config

import android.text.TextUtils
import com.zz.framework.core.ext.*

/**
 * Copyright © 2020 zanezhao All rights reserved.
 * Created by zanezhao on 2020/2/29 9:31 PM.
 * @author: zanezhao 1820022519@qq.com
 * @version: V1.0
 */
object GlobalSetting {
    // 读超时
    const val READ_TIME_OUT = 60L
    // 写超时
    const val WRITE_TIME_OUT = 60L
    // 连接超时
    const val CONNECT_TIME_OUT = 30L

    private const val SP_NAME = "SHARED_PREFERENCES_NAME"
    private const val SP_TOKEN = "SHARED_PREFERENCES_TOKEN"
    private const val SP_USER = "SHARED_PREFERENCES_USER"
    private const val SP_USER_ID = "SHARED_PREFERENCES_USER_ID"
    private const val SP_USERNAME = "SHARED_PREFERENCES_USERNAME"
    private const val SP_PASSWORD = "SHARED_PREFERENCES_PASSWORD"
    private const val SP_DEVICE_ID = "SP_DEVICE_ID"




    fun getDeviceId():String{
        return sp(SP_NAME).getString(SP_DEVICE_ID,"")?:""
    }
    fun setDeviceId(deviceId:String?=""){
        //为空才更新
        if (TextUtils.isEmpty(getDeviceId())) {
            sp(SP_NAME).putString(SP_DEVICE_ID, deviceId)
        }
    }


    fun getToken():String{
        return sp(SP_NAME).getString(SP_TOKEN,"")?:""
    }
    fun setToken(token:String?=""){
        sp(SP_NAME).putString(SP_TOKEN,token)
    }
    fun getUser():String{
        return sp(SP_NAME).getString(SP_USER,"{}")?:"{}"
    }

    inline fun <reified T> getUserEntity():T{
        return getUser().fromJson<T>()
    }

    fun setUser(userStr:String?=""){
        sp(SP_NAME).putString(SP_USER,userStr)
    }

    fun setUserId(userId:String?=""){
        sp(SP_NAME).putString(SP_USER_ID,userId)
    }
    fun getUserId():String{
        return sp(SP_NAME).getString(SP_USER_ID,"")?:""
    }

    private var mLoginActivityClass: Class<*>? = null
    fun setLoginActivity(mLoginActivity: Class<*>?) {
        mLoginActivityClass = mLoginActivity
    }
    fun getLoginActivityClass(): Class<*>? {
        return mLoginActivityClass
    }

}